// pages/team-auditing-list/team-auditing-list.js
import {
    getNewTeamList,
    setTeamAdopt,
    setTeamFail
} from '../../api/app'
import user from '../../utils/user'
const app = getApp()
Page({
    data: {
        list: [],
        pageNum: 1,
        hasNextPage: true
    },
    onLoad(options) {},
    onReady() {

    },
    onShow() {
        this.setData({
            list: [],
            pageNum: 1
        })
        this.getNewTeamList()
    },
    async getNewTeamList() {
        const result = await getNewTeamList({
            companyId: user.companyId,
            pageSize: 50,
            pageNum: this.data.pageNum
        })
        console.log(result, 'result')
        if (!result.hasNextPage) {
            this.setData({
                hasNextPage: result.hasNextPage
            })
        }
        const arr = []
        arr.push(...this.data.list)
        arr.push(...result.list)
        this.setData({
            list: arr
        })
    },
    goMemberDetail(event) {
        const {
            id
        } = event.currentTarget.dataset
        wx.navigateTo({
            url: '/pages/team-auditing-detail/team-auditing-detail?id=' + id,
        })
    },
    async onSetTeamAdopt(event) {
        console.log(event, 'event')
        const {
            id
        } = event.currentTarget.dataset
        // app.confirm('确定通过吗').then(async () => {
        await setTeamAdopt({
            id: id
        })
        await app.toast('成功通过')
        this.setData({
            list: [],
            pageNum: 1
        })
        await this.getNewTeamList()
        // })

    },
    async onSetTeamFail(event) {
        console.log(event, 'event')
        const {
            id
        } = event.currentTarget.dataset
        app.confirm('确定忽略吗').then(async () => {
            await setTeamFail({
                id: id
            })
            await app.toast('忽略成功')
            this.setData({
                list: [],
                pageNum: 1
            })
            await this.getNewTeamList()
        })
    },
    threshold() {
        if (!this.data.hasNextPage) {
            return
        }
        this.setData({
            pageNum: this.data.pageNum += 1
        })
        this.getNewTeamList()
    }
})